home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / CBGRX103.ZIP / contrib / libgrx / test / blittest.c < prev    next >
Text File  |  1993-12-06  |  7KB  |  300 lines

  1. /**
  2.  ** BLITTEST.C
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24.  
  25. #include "test.h"
  26. #include <stdlib.h>
  27. #include <string.h>
  28.  
  29. int BWW = 83;
  30. int BHH = 50;
  31.  
  32. void drbox(GrContext *src,int x,int y)
  33. {
  34.     int c1 = GrAllocColor(0,0,255);
  35.     int c2 = GrAllocColor(255,0,0);
  36.     int xx;
  37.  
  38.     GrClearScreen(c1);
  39.     GrSetContext(src);
  40.     GrSetClipBox(x-10,y-10,x+BWW-1+10,y+BHH-1+10);
  41.     GrClearClipBox(c2);
  42.     GrSetClipBox(x,y,x+BWW-1,y+BHH-1);
  43.     GrClearClipBox(GrBlack());
  44.     GrBox(x,y,x+BWW-1,y+BHH-1,GrWhite());
  45.     for(xx = x; xx < x+BWW; xx += 5) {
  46.         GrLine(xx,y,xx+BHH,y+BHH,GrWhite());
  47.         GrLine(xx,y,xx-BHH,y+BHH,GrWhite());
  48.     }
  49.     GrSetContext(NULL);
  50.     GrResetClipBox();
  51. }
  52.  
  53. void doblits(GrContext *src,int x,int y)
  54. {
  55.     int xx = 300;
  56.     int yy = 20;
  57.     int ii;
  58.  
  59.     for(ii = 0; ii < 8; ii++) {
  60.         GrBitBlt(NULL,xx,yy,src,x,y,x+BWW-1,y+BHH-1,GrWRITE);
  61.         xx++;
  62.         yy += (BHH + 5);
  63.     }
  64. }
  65.  
  66. void bltest(GrContext *src,int x,int y)
  67. {
  68.     int ii;
  69.  
  70.     for(ii = 0; ii < 8; ii++) {
  71.         drbox(src,x,y);
  72.         doblits(src,x,y);
  73.         getkey();
  74.         x++;
  75.     }
  76. }
  77.  
  78. void blxtest(void)
  79. {
  80.     GrContext memc;
  81.     int cw = (BWW + 28) & ~7;
  82.     int ch = BHH + 20;
  83.  
  84.     bltest(NULL,GrScreenX()-BWW-8,GrScreenY()-BHH);
  85.     bltest(NULL,0,0);
  86. #ifdef __GNUC__
  87.     {
  88.         /*
  89.          * test stray memory references after the end of a context!!
  90.          */
  91.         long size = GrContextSize(cw,ch);
  92.         char *ptr = (char *)(((int)sbrk(0) + 10000 + size) & ~ 4095) - 1;
  93.  
  94.         brk(ptr);
  95.         GrCreateContext(cw,ch,(ptr + 1 - size),&memc);
  96.         bltest(&memc,cw-BWW-8,ch-BHH);
  97.         /*
  98.          * prove that the next byte is really inaccessible
  99.          */
  100.         if((Argc > 0) && (strcmp(Argv[0],"crash") == 0)) {
  101.         Argc |= *ptr++;        /* should be OK */
  102.         Argc |= *ptr++;        /* should crash */
  103.         }
  104.     }
  105. #endif
  106. #ifdef __TURBOC__
  107.     GrCreateContext(cw,ch,NULL,&memc);
  108.     bltest(&memc,cw-BWW-8,ch-BHH);
  109. #endif
  110. }
  111.  
  112. TESTFUNC(blittest)
  113. {
  114.     int x = GrSizeX();
  115.     int y = GrSizeY();
  116.     int ww = (x * 2) / 3;
  117.     int wh = (y * 2) / 3;
  118.     int c,ii,jj,bg;
  119.     GrFBoxColors bcolors,ocolors,icolors;
  120.     int wdt = ww / 150;
  121.     int bw = x / 17;
  122.     int bh = y / 17;
  123.     int bx,by;
  124.  
  125.     GrContext *save = GrCreateSubContext(0,0,GrMaxX(),GrMaxY(),NULL,NULL);
  126.     GrContext *tile = GrCreateContext(bw,bh,NULL,NULL);
  127.  
  128.     blxtest();
  129.     BWW = 3;
  130.     blxtest();
  131.  
  132.     bcolors.fbx_intcolor = GrAllocColor(160,100,30);
  133.     bcolors.fbx_topcolor = GrAllocColor(240,150,45);
  134.     bcolors.fbx_leftcolor = GrAllocColor(240,150,45);
  135.     bcolors.fbx_rightcolor = GrAllocColor(80,50,15);
  136.     bcolors.fbx_bottomcolor = GrAllocColor(80,50,15);
  137.  
  138.     ocolors.fbx_intcolor = GrAllocColor(0,120,100);
  139.     ocolors.fbx_topcolor = GrAllocColor(0,180,150);
  140.     ocolors.fbx_leftcolor = GrAllocColor(0,180,150);
  141.     ocolors.fbx_rightcolor = GrAllocColor(0,90,60);
  142.     ocolors.fbx_bottomcolor = GrAllocColor(0,90,60);
  143.  
  144.     icolors.fbx_intcolor = bg = GrAllocColor(30,30,30);
  145.     icolors.fbx_bottomcolor = GrAllocColor(0,180,150);
  146.     icolors.fbx_rightcolor = GrAllocColor(0,180,150);
  147.     icolors.fbx_leftcolor = GrAllocColor(0,90,60);
  148.     icolors.fbx_topcolor = GrAllocColor(0,90,60);
  149.  
  150.     c = GrAllocColor(250,250,0);
  151.  
  152.     for(ii = 0,by = -(bh/3); ii < 18; ii++) {
  153.         for(jj = 0,bx = -(bw/2); jj < 18; jj++) {
  154.         GrFramedBox(bx+2*wdt,by+2*wdt,bx+bw-2*wdt-1,by+bh-2*wdt-1,2*wdt,&bcolors);
  155.         bx += bw;
  156.         }
  157.         by += bh;
  158.     }
  159.  
  160.     GrFramedBox(ww/4-5*wdt-1,wh/4-5*wdt-1,ww/4+5*wdt+ww+1,wh/4+5*wdt+wh+1,wdt,&ocolors);
  161.     GrFramedBox(ww/4-1,wh/4-1,ww/4+ww+1,wh/4+wh+1,wdt,&icolors);
  162.  
  163.     GrSetClipBox(ww/4,wh/4,ww/4+ww,wh/4+wh);
  164.     drawing(ww/4,wh/4,ww,wh,c,bg);
  165.     getkey();
  166.  
  167.     GrClearScreen(0);
  168.     GrSetContext(save);
  169.  
  170.     bx = -(bw/2) + 15*bw;
  171.     by = -(bh/3) + 15*bh;
  172.  
  173.     GrFramedBox(bx+2*wdt,by+2*wdt,bx+bw-2*wdt-1,by+bh-2*wdt-1,2*wdt,&bcolors);
  174.  
  175.     for(ii = 0,by = -(bh/3); ii < 18; ii++) {
  176.         for(jj = 0,bx = -(bw/2); jj < 18; jj++) {
  177.         if((ii != 15) || (jj != 15)) {
  178.             GrBitBlt(save,
  179.             bx,by,
  180.             save,
  181.             -(bw/2) + 15*bw,
  182.             -(bh/3) + 15*bh,
  183.             -(bw/2) + 15*bw + bw - 1,
  184.             -(bh/3) + 15*bh + bh - 1,
  185.             GrWRITE
  186.             );
  187.         }
  188.         bx += bw;
  189.         }
  190.         by += bh;
  191.     }
  192.  
  193.     GrFramedBox(ww/4-5*wdt-1,wh/4-5*wdt-1,ww/4+5*wdt+ww+1,wh/4+5*wdt+wh+1,wdt,&ocolors);
  194.     GrFramedBox(ww/4-1,wh/4-1,ww/4+ww+1,wh/4+wh+1,wdt,&icolors);
  195.  
  196.     GrSetClipBox(ww/4,wh/4,ww/4+ww,wh/4+wh);
  197.     drawing(ww/4,wh/4,ww,wh,c,bg);
  198.     getkey();
  199.  
  200.  
  201.     GrBitBlt(tile,
  202.         0,0,
  203.         save,
  204.         -(bw/2) + 15*bw,
  205.         -(bh/3) + 15*bh,
  206.         -(bw/2) + 15*bw + bw - 1,
  207.         -(bh/3) + 15*bh + bh - 1,
  208.         GrWRITE
  209.     );
  210.     GrSetContext(tile);
  211.     GrFramedBox(2*wdt,2*wdt,bw-2*wdt-1,bh-2*wdt-1,2*wdt,&bcolors);
  212.  
  213.     GrClearScreen(0);
  214.     GrSetContext(save);
  215.  
  216.     for(ii = 0,by = -(bh/3); ii < 18; ii++) {
  217.         for(jj = 0,bx = -(bw/2); jj < 18; jj++) {
  218.         GrBitBlt(save,
  219.             bx,by,
  220.             tile,
  221.             0,0,
  222.             bw-1,bh-1,
  223.             GrWRITE
  224.         );
  225.         bx += bw;
  226.         }
  227.         by += bh;
  228.     }
  229.  
  230.     GrFramedBox(ww/4-5*wdt-1,wh/4-5*wdt-1,ww/4+5*wdt+ww+1,wh/4+5*wdt+wh+1,wdt,&ocolors);
  231.     GrFramedBox(ww/4-1,wh/4-1,ww/4+ww+1,wh/4+wh+1,wdt,&icolors);
  232.  
  233.     GrSetClipBox(ww/4,wh/4,ww/4+ww,wh/4+wh);
  234.     drawing(ww/4,wh/4,ww,wh,c,bg);
  235.  
  236.     getkey();
  237.     GrResetClipBox();
  238.     GrBitBlt(NULL,
  239.        60,60,
  240.        NULL,
  241.        20,20,
  242.        GrSizeX() - 40,
  243.        GrSizeY() - 40,
  244.        GrWRITE
  245.     );
  246.  
  247.     getkey();
  248.  
  249.     GrBitBlt(NULL,
  250.        10,10,
  251.        NULL,
  252.        60,60,
  253.        GrSizeX() - 40,
  254.        GrSizeY() - 40,
  255.        GrWRITE
  256.     );
  257.  
  258.     getkey();
  259.  
  260.     GrSetContext(tile);
  261.     GrClearContext(0);
  262.  
  263.     GrBitBlt(tile,
  264.         0,0,
  265.         save,
  266.         -(bw/2),
  267.         -(bh/3),
  268.         -(bw/2) + 15*bw + bw - 1,
  269.         -(bh/3) + 15*bh + bh - 1,
  270.         GrWRITE
  271.     );
  272.  
  273.     GrSetContext(save);
  274.     GrClearScreen(0);
  275.  
  276.     for(ii = 0,by = -(bh/3); ii < 18; ii++) {
  277.         for(jj = 0,bx = -(bw/2); jj < 18; jj++) {
  278.         GrBitBlt(save,
  279.             bx,by,
  280.             tile,
  281.             0,0,
  282.             bw-1,bh-1,
  283.             GrWRITE
  284.         );
  285.         bx += bw;
  286.         }
  287.         by += bh;
  288.     }
  289.  
  290.     GrFramedBox(ww/4-5*wdt-1,wh/4-5*wdt-1,ww/4+5*wdt+ww+1,wh/4+5*wdt+wh+1,wdt,&ocolors);
  291.     GrFramedBox(ww/4-1,wh/4-1,ww/4+ww+1,wh/4+wh+1,wdt,&icolors);
  292.  
  293.     GrSetClipBox(ww/4,wh/4,ww/4+ww,wh/4+wh);
  294.     drawing(ww/4,wh/4,ww,wh,c,bg);
  295.  
  296.     getkey();
  297.  
  298. }
  299.  
  300.